package main

import (
	"fmt"
)

// struct 是值类型结构体, 内存中每个字段都是连续的，使用this或self作为method的形参命名
type userInfo struct {
	name   string
	age    int
	height float32
	hobbie []string
	other  map[string]interface{}
}

// 结构体可以相互转换，但是前提需要相同字段（数量也要相同)
type people struct {
	name   string
	age    int
	height float32
	hobbie []string
	other  map[string]interface{}
}

// go 没有类概念,type自定义类型不同不可赋值，强制转换可以赋值
func main() {
	type numbers int
	var number numbers
	fmt.Println(number)
	//调用结构体
	var human userInfo
	human.age = 18
	human.height = 1.88
	human.name = "frank"
	human.hobbie = []string{"coding", "study"}
	human.other = map[string]interface{}{
		"salary": 100,
		"job":    "student",
	}
	//简单调用
	me := userInfo{
		other: map[string]interface{}{"this": 11111},
	}
	fmt.Print(human, me, "--------")
	//new 指针调用结构体
	var you *userInfo
	you = new(userInfo)
	(*you).age = 22
	(*you).name = "levia"
	you.hobbie = []string{"java", "php"}
	fmt.Println(you)
	//使用&调用结构体
	var them *userInfo = &userInfo{
		name:   "david",
		age:    90,
		height: 1.22,
		hobbie: []string{"hh"},
	}
	fmt.Printf("this is %p", them)
	//值类型验证
	user1 := userInfo{
		other: map[string]interface{}{"wwww": 6666},
	}
	user2 := user1 //内存地址不同
	fmt.Printf("user1 = %p, user2 = %p", &user1, &user2)
	user3 := people{other: map[string]interface{}{"wwww": 6666}}
	//结构体转换
	user2 = userInfo(user3)
	fmt.Print("-------", user3)
}
